//
//  ViewController.m
//  通讯录StoryBoard
//
//  Created by dllo on 16/3/28.
//  Copyright © 2016年 付冬梅. All rights reserved.
//

#import "ViewController.h"
#import "TableViewCellOfContact.h"

@interface ViewController ()<UITableViewDataSource, UITableViewDelegate>


@property (nonatomic, retain) NSDictionary *dic;
@property (nonatomic, retain) NSArray *allKeysArr;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self dataHandle];
}

- (void)dataHandle {
    NSString *path = [[NSBundle mainBundle] pathForResource:@"DLS160101" ofType:@"plist"];
    self.dic = [NSDictionary dictionaryWithContentsOfFile:path];
    self.allKeysArr = [[self.dic allKeys] sortedArrayUsingSelector:@selector(compare:)];
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 100;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    NSLog(@"%ld", self.allKeysArr.count);
    return self.allKeysArr.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSString *key = self.allKeysArr[section];
    NSArray *arr = [self.dic objectForKey:key];
    return arr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    TableViewCellOfContact *cell = [tableView dequeueReusableCellWithIdentifier:@"pool"];
    NSString *key = self.allKeysArr[indexPath.section];
    NSArray *arr = [self.dic objectForKey:key];
    NSDictionary *dic = arr[indexPath.row];
    cell.nameLabel.text = dic[@"name"];
    cell.phoneLabel.text = dic[@"phoneNumber"];
    NSLog(@"%@", cell.phoneLabel.text);
    
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
